<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *订单管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
$return['status']=$this->ding_status;
$tabs=array(
	array('op'=>'list','query'=>'status=100','title'=>'全部拼单'),
	array('op'=>'list','query'=>'status=1','title'=>'拼单中'),
	array('op'=>'list','query'=>'status=2','title'=>'拼单成功'),
	array('op'=>'list','query'=>'status=3','title'=>'拼单失败'),
); 
if($_RQ['op']=='list'){
	$return['params']=array('api_pluginname'=>'jy_pingdd_pin');
	$params=array('uniacid'=>$_SESSION['uniacid'],'api_pluginname'=>'jy_pingdd_pin');
	if(isset($_RQ['status']) && $_RQ['status']!=100){
		$params['status']=intval($_RQ['status']);
		$return['params']['status']=intval($_RQ['status']);
	}
	//我的团
	//先查询我的订单
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$list=pdo_getslice('jy_weishop_order_ding',$params,array($pindex,$psize),$total,$fields,'','createtime desc');
	if($list){
		foreach($list as $k=>&$item){
			$item['goods']=pdo_get('jy_weishop_goods',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['goodsid']));
			$item['goods']=$this->model('model')->up_price($item['goods'],$return['pluginset'],true);
			if(!$item['goods']['id']){
				unset($teams[$k]);
			}
			$item['order']=pdo_get('jy_weishop_order_ding',array('uniacid'=>$_SESSION['uniacid'],'teamid'=>$item['id'],'mid'=>$item['mid']));
			$item['member']=cfc('core')->member_show($item['mid']);
			//到期时间
			$item['endtime']=$item['goods']['grouptime']*60*60+$item['createtime'];
			$item['goodstitle']=$item['goods']['title'];
			$item['groupnum']=pdo_count('jy_weishop_order_ding',array('uniacid'=>$_SESSION['uniacid'],'status'=>1,'teamid'=>$item['teamid']));
			$item['teamnum']=$item['goods']['teamnum'];
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','edit'=>false,'del_one'=>false,'delall'=>false,'list'=>array(
			array('name'=>'id','title'=>'拼ID','type'=>'string'),
			array('name'=>'member','title'=>'会员信息_Member','type'=>'member'),
			array('name'=>'groupnum','title'=>'已拼单人数','type'=>'string'),
			array('name'=>'teamnum','title'=>'成团人数','type'=>'string'),
			array('name'=>'goodstitle','title'=>'商品名称','type'=>'string'),
			array('name'=>'createtime','title'=>'开团时间','type'=>'time'),
			array('name'=>'endtime','title'=>'到期时间','type'=>'time'),
			array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'status'),
		)),
		'search'=>array(
			array('name'=>'id','title'=>'团ID','type'=>'string','width'=>15),
			array('name'=>'nickname','title'=>'团长昵称','type'=>'string','width'=>15),
		)
	);
	$return['htmls']=$htmls;	
	exi($return);
}
